package com.wuseguang.springcloud.dao.mapper;

import com.wuseguang.springcloud.entity.Attend;
import com.wuseguang.springcloud.entity.Classes;
import com.wuseguang.springcloud.entity.Grade;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 班牌人脸或刷卡考勤 Mapper 接口
 * </p>
 *
 * @author
 * @since 2020-03-02
 */
@Mapper
public interface AttendMapper {


    @Select(value = "  SELECT g.id ,g.name  FROM attendance_group a,attendance_group_user u,student t,classes s,grade g WHERE " +
            "  a.id=u.attend_group_id AND u.userid=t.id AND t.class_id=s.id  AND a.id=#{attendGroupId} AND a.school_id=#{schoolId} AND g.id=s.grade_id GROUP BY g.id")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "id", property = "list", many = @Many(select = "getClasses", fetchType = FetchType.EAGER))
    })
    List<Grade> getGrade(@Param("attendGroupId") String attendGroupId, @Param("schoolId") String schoolId);


    @Select(value = "select s.id,s.name from classes s,attendance_group_user u,student t where s.id=t.class_id and u.userid=t.id and s.grade_id=#{id} GROUP BY s.id ")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "name", property = "name")
    })
    List<Classes> getClasses(int id);

}
